package tritop.android.naturalselectionnews;

import java.util.ArrayList;



import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Gallery.LayoutParams;

public class ImageAdapter extends BaseAdapter {
	private int mGalleryItemBackground;
    private Context mContext;
    public Integer[] mImgs=
    {
    	
        R.drawable.marine_malemarine_concept,
        R.drawable.marine_malemarine_render,
        R.drawable.ns2_armory,
        R.drawable.ns2_biodome_hiveroom,
        R.drawable.ns2_concept_armory,
        R.drawable.ns2_concept_femalemarine,
        R.drawable.ns2_concept_gorge,
        R.drawable.ns2_concept_hive,
        R.drawable.ns2_concept_infantryportal,
        R.drawable.ns2_concept_onos,
        R.drawable.ns2_concept_resourcetower,
        R.drawable.ns2_concept_skulk,
        R.drawable.ns2_concept_skulkinvent,
        R.drawable.ns2_environment_generatorroom,
        R.drawable.ns2_environment_modularmachinery,
        R.drawable.ns2_environment_railcar,
        R.drawable.ns2_environment_specimenlab,
        R.drawable.ns2_environment_tramrepair,
        R.drawable.ns2_gorge,
        R.drawable.ns2_infantryportal,
        R.drawable.ns2_mining_centraldrilling,
        R.drawable.ns2_onos,
        R.drawable.ns2_refinery_hallway,
        R.drawable.ns2_refinery_lavafalls,
        R.drawable.ns2_refinery_moltenmetalroom,
        R.drawable.ns2_refinery_windows,
        R.drawable.ns2_resourcetower,
        R.drawable.ns2_skulk
       
   };
    
    public Integer[] mImgsThumbs=
    {
    	
        R.drawable.thumb_marine_malemarine_concept,
        R.drawable.thumb_marine_malemarine_render,
        R.drawable.thumb_ns2_armory,
        R.drawable.thumb_ns2_biodome_hiveroom,
        R.drawable.thumb_ns2_concept_armory,
        R.drawable.thumb_ns2_concept_femalemarine,
        R.drawable.thumb_ns2_concept_gorge,
        R.drawable.thumb_ns2_concept_hive,
        R.drawable.thumb_ns2_concept_infantryportal,
        R.drawable.thumb_ns2_concept_onos,
        R.drawable.thumb_ns2_concept_resourcetower,
        R.drawable.thumb_ns2_concept_skulk,
        R.drawable.thumb_ns2_concept_skulkinvent,
        R.drawable.thumb_ns2_environment_generatorroom,
        R.drawable.thumb_ns2_environment_modularmachinery,
        R.drawable.thumb_ns2_environment_railcar,
        R.drawable.thumb_ns2_environment_specimenlab,
        R.drawable.thumb_ns2_environment_tramrepair,
        R.drawable.thumb_ns2_gorge,
        R.drawable.thumb_ns2_infantryportal,
        R.drawable.thumb_ns2_mining_centraldrilling,
        R.drawable.thumb_ns2_onos,
        R.drawable.thumb_ns2_refinery_hallway,
        R.drawable.thumb_ns2_refinery_lavafalls,
        R.drawable.thumb_ns2_refinery_moltenmetalroom,
        R.drawable.thumb_ns2_refinery_windows,
        R.drawable.thumb_ns2_resourcetower,
        R.drawable.thumb_ns2_skulk
        
   };
    
    
    
    
    
    
    public ImageAdapter(Context ctx){
    	mContext = ctx;
        TypedArray a = ctx.obtainStyledAttributes(R.styleable.GalleryStyle);
        mGalleryItemBackground = a.getResourceId(R.styleable.GalleryStyle_android_galleryItemBackground, 0);
        a.recycle();
    }
    
	@Override
	public int getCount() {
		return mImgsThumbs.length;
	}

	@Override
	public Object getItem(int position) {
		return mImgs[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView!=null){
			ImageView imgv=(ImageView)convertView;
			BitmapDrawable bmdraw=(BitmapDrawable)imgv.getDrawable();
			bmdraw.getBitmap().recycle();
			imgv.setImageResource(mImgsThumbs[position]);
			return imgv;
		}
		ImageView i = new ImageView(mContext);
		i.setImageBitmap(BitmapFactory.decodeStream(mContext.getResources().openRawResource(mImgsThumbs[position])));
        //i.setImageResource(mImgsThumbs[position]);
        i.setAdjustViewBounds(true);
        i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        return i;
	}

}
